//
//  OrderPopViewController.m
//  体育商城
//
//  Created by  on 2022/9/24.
//

#import "OrderPopViewController.h"

@interface OrderPopViewController ()
@property (strong, nonatomic) IBOutlet UIView *bgview;
@property (strong, nonatomic) IBOutlet UIButton *cancelBtn;
@property (strong, nonatomic) IBOutlet UILabel *status;
@property (strong, nonatomic) IBOutlet UIImageView *img;
@property (strong, nonatomic) IBOutlet UILabel *content;
@property (strong, nonatomic) IBOutlet UILabel *detail;
@property (strong, nonatomic) IBOutlet UILabel *tips;
@property (strong, nonatomic) IBOutlet UIButton *btn;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *imgTop;
@end

@implementation OrderPopViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
}
- (void)initUI{
    self.style = OrderPopStyleShip;
    CGRect bounds = CGRectMake(0, 0, SCREEN_WIDTH, self.bgview.frame.size.height);
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(20, 20)];
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.frame = bounds;
    layer.path = path.CGPath;
    self.bgview.layer.mask = layer;
}
- (void)setStyle:(OrderPopStyle)style{
    _style = style;
    switch (style){
        case OrderPopStyleShip:{
            self.imgTop.constant = 20;
            self.status.hidden = YES;
            self.content.hidden = NO;
            self.detail.hidden = NO;
            self.btn.hidden = YES;
            self.tips.hidden = NO;
            self.img.image = [UIImage imageNamed:@"成功"];
            self.content.text = LS(@"已提醒买家尽快发货");
            int stamp = [self.model.orderID intValue] + 7 * 3600 * 24;
            stamp = stamp < 1000000 ? [[NSDate currentTimeStamp:@"yyyy/MM/dd"] intValue] : stamp;
            NSString *time = [NSDate transToDate:@"yyyy/MM/dd" :stamp];
            self.detail.text = [NSString stringWithFormat:LS(@"卖家应在%@前发货，请耐心等待"),time];
            self.tips.text = LS(@"联系商家");
        }
            break;
        case OrderPopStyleRefundFail:
        case OrderPopStyleRefundSuccess:{
            self.imgTop.constant = 44;
            self.status.hidden = NO;
            self.content.text = style == OrderPopStyleRefundSuccess ? LS(@"退款中...") : LS(@"退款失败");
            self.detail.hidden = YES;
            self.tips.hidden = YES;
            NSString * title = style == OrderPopStyleRefundSuccess ? LS(@"确定") : LS(@"联系商家");
            [self.btn setTitle:title forState:UIControlStateNormal];
            NSString * name = style == OrderPopStyleRefundSuccess ? @"成功" : @"失败";
            self.img.image = [UIImage imageNamed:name];
        }
            break;
            
    }
}
- (IBAction)actionForBtn:(UIButton *)sender {
    switch (sender.tag){
        case 201:///取消
            [self dismissViewControllerAnimated:true completion:nil];
        case 202:///联系商家/确定
            [self dismissViewControllerAnimated:NO completion:nil];
            if (self.block) {
                self.block(sender.currentTitle);
            }
        default:
            break;
    }
}

@end
